package impl.persons;

import framework.Business;
import framework.PersonAdapter;

import java.util.HashMap;
import java.util.Map;

import org.apache.log4j.Logger;

/**
 * Implements "Tit For Tat" personal strategy.
 *
 * @author Denis DIR Rozhnev
 */
public class TitForTat extends PersonAdapter {
    static Logger LOG = Logger.getLogger(TitForTat.class);
    private Map<Object, Integer> history = new HashMap<Object, Integer>();

    public String getShortName() {
        return "TFT";
    }

    @Override
    public int deal(Object id) {
        if (history.containsKey(id)) {
            int x = history.get(id);
//            LOG.debug("Person: " + id + " History: " + x);
            return x;
        }
//        LOG.debug("Person: " + id + " COOPERATING");
        return Business.COOPERATE;
    }

    @Override
    public void dealed(Object id, int deal) {
        history.put(id, deal);
    }
}